//
//  ListAuthorViewController.m
//  AloTruyen
//
//  Created by vominhthong on 10/11/14.
//  Copyright (c) 2014 Khoai Nguyen Minh. All rights reserved.
//

#import "ListAuthorViewController.h"
#import "ListBookCell.h"
#import "AuthorCell.h"
@interface ListAuthorViewController () <UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) NSMutableArray *listBook;
@property (nonatomic,weak) IBOutlet UITableView *tableView;

@end

@implementation ListAuthorViewController
#pragma mark - Initialize
-(NSMutableArray *)listBook{
    if (!_listBook) {
        _listBook = [NSMutableArray array];
    }
    return _listBook;
}
#pragma mark - Customize Bar
-(void)customizeBar{
    self.leftButtonImageName = @"list";
    self.rightButtonImageName = @"icon_filter_az";
    self.titleLabelString = @"DANH SÁCH TÁC GIẢ";
}
#pragma mark - Button Action
-(void)didTouchedOnLeftButton:(id)sender{
    [self.navigationController.revealController showViewController:self.navigationController.revealController.leftViewController animated:YES completion:^(BOOL finished) {
        
    }];
}

- (void)viewDidLoad
{
    [self customizeBar];
    [super viewDidLoad];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 60;
    [appDelegate.dataCenter getAuthorListWithBlock:^(id result, id error) {
        if (result) {
            [self.listBook addObjectsFromArray:result];
            [self.tableView reloadData];
        }else{
            [NLUtils showAlertWithMessage:error];
        }
    }];

    // Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - TableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.listBook.count;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"ListAuthor";
    AuthorCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[IBHelper sharedUIHelper]loadViewNib:@"AuthorCell"];
    }
    cell.authorModal = self.listBook[indexPath.row];
//    cell.aloTruyen = self.listBook[indexPath.row];
    
    return cell;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
